define([
    'app',
    'css!css/views/dashboard.css'
], function(app) {
    app.controller('HomeController', ['Config', 'PropertyService', function(Config, PropertyService) {
        var self = this;
        self.slides = [];
        self.loaded = false;

        self.init = function() {
            PropertyService.getPropertyByPage({
                offset: 0,
                limit: 6,
                orderBy: ['-buy_date']
            }).then(function(resp) {
                var images = resp.data.data;
                if (angular.isArray(images) && images.length > 0) {
                    angular.forEach(images, function(image, index) {
                        self.slides.push({
                            image: Config.imageBaseUrl + image.imageUrl,
                            text: image.name,
                            id: image.id,
                            index: index
                        });
                    });
                    self.loaded = true;
                }
            });
        };
    }]);
});
